package com.gwclh.personnel.controller;


import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.gwclh.personnel.bean.ResultVo;
import com.gwclh.personnel.domain.PageDomain;
import com.gwclh.personnel.entity.Employee;
import com.gwclh.personnel.entity.StaTransfer;
import com.gwclh.personnel.entity.Station;
import com.gwclh.personnel.service.IEmployeeService;
import com.gwclh.personnel.service.IStaTransferService;
import com.gwclh.personnel.service.IStationService;
import com.gwclh.personnel.utils.ShiroUtil;
import com.gwclh.personnel.vo.stationvo.StaTransFerVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 岗位调转记录表
 * 前端控制器
 * </p>
 *
 * @author gzhhh
 * @since 2020-07-24
 */
@RestController
@RequestMapping("/sta-transfer")
@Api("岗位调转")
public class StaTransferController extends BaseController {
    @Autowired
    IStaTransferService staTransferService;
    @Autowired
    IEmployeeService employeeService;

    @Autowired
    IStationService stationService;
    @GetMapping("")
    @ApiOperation("岗位调转列表")
    public ResultVo listStaTransFer(StaTransFerVo staTransFerVo, HttpServletRequest request) {
        PageDomain pageDomain = getPageParams(request);
        return staTransferService.listStaTrans(pageDomain, staTransFerVo);
    }


    @PostMapping("")
    @ApiOperation(value = "添加岗位调转记录")
    public ResultVo addStaTran(@Validated @RequestBody StaTransfer staTransfer) {

        return staTransferService.addTran(staTransfer);
    }
    
    @GetMapping("/data")
    public ResultVo staTransData() {
        List<Map<String, Object>> transData = staTransferService.getTransData();
        return ResultVo.success(transData);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除岗位调转记录")
    public ResultVo delStaTranLog(@PathVariable Integer id){
        Assert.isTrue(staTransferService.removeById(id),"删除失败");
        staTransferService.removeById(id);
        return ResultVo.success();

    }

}
